﻿//Created by Action Script Viewer - http://www.buraks.com/asv
package Display.FactoryUI {
    import flash.events.*;
    import Engine.Managers.*;
    import flash.display.*;
    import Events.*;
    import flash.utils.*;
    import Display.DialogUI.*;
    import Classes.*;
    import Display.*;

    public class SuppliesDialog extends GenericDialog {

        public static var assetDict:Dictionary;

        protected var m_items:Array;
        protected var m_contractItemType:String;

        public function SuppliesDialog(_arg1:String, _arg2:String="", _arg3:String="contract", _arg4:int=0, _arg5:Function=null, _arg6:Boolean=true, _arg7:int=0){
            super(_arg1, _arg2, _arg4, _arg5, _arg2, "", true);
            this.m_contractItemType = _arg3;
        }
        override protected function loadAssets():void{
            var _local1:String = Global.getAssetURL("assets/dialogs/SuppliesAssets.swf");
            LoadingManager.load(_local1, this.onAssetsLoaded);
        }
        override protected function onAssetsLoaded(_arg1:Event=null):void{
            var _local2:LoaderInfo = (_arg1.target as LoaderInfo);
            SuppliesDialog.assetDict = new Dictionary(true);
            var _local3:Object = _local2.content;
            SuppliesDialog.assetDict["close_button"] = _local3.close_button;
            SuppliesDialog.assetDict["left_green_arrow"] = _local3.left_green_arrow;
            SuppliesDialog.assetDict["radial_button_selected"] = _local3.radial_button_selected;
            SuppliesDialog.assetDict["radial_button_unselected"] = _local3.radial_button_unselected;
            SuppliesDialog.assetDict["right_green_arrow"] = _local3.right_green_arrow;
            SuppliesDialog.assetDict["supplies_background"] = _local3.supplies_background;
            SuppliesDialog.assetDict["supplies_card"] = _local3.supplies_card;
            SuppliesDialog.assetDict["whats_this_button"] = _local3.whats_this_button;
            SuppliesDialog.assetDict["star"] = _local3.star;
            SuppliesDialog.assetDict["icon_bg"] = _local3.icon_bg;
            SuppliesDialog.assetDict["coin_small"] = _local3.coin_small;
            SuppliesDialog.assetDict["coin_big"] = _local3.coin_big;
            SuppliesDialog.assetDict["truck"] = _local3.truck;
            SuppliesDialog.assetDict["forklift"] = _local3.forklift;
            SuppliesDialog.assetDict["supplies_lockedcard"] = _local3.supplies_lockedcard;
            SuppliesDialog.assetDict["slot_locked"] = _local3.slot_locked;
            SuppliesDialog.assetDict["slot_cash"] = _local3.slot_cash;
            SuppliesDialog.assetDict["lock_bg"] = _local3.lock_bg;
            SuppliesDialog.assetDict["cash"] = _local3.cash;
            this.m_items = Global.gameSettings.getBuyableItems(this.m_contractItemType);
            m_jpanel = new SuppliesDialogView(SuppliesDialog.assetDict, this.m_items, m_title, m_callback);
            m_jpanel.addEventListener(DataItemEvent.MARKET_BUY, this.onContractClick, false, 0, true);
            m_jpanel.addEventListener(Event.CLOSE, this.onCloseClick, false, 0, true);
            finalizeAndShow();
        }
        private function onCloseClick(_arg1:Event=null):void{
            this.close();
            m_jpanel.removeEventListener(DataItemEvent.MARKET_BUY, this.onContractClick);
            m_jpanel.removeEventListener(Event.CLOSE, this.onCloseClick);
        }
        private function onContractClick(_arg1:DataItemEvent):void{
            SoundManager.chooseAndPlaySound(["click1", "click2", "click3"]);
            var _local2:Item = _arg1.item;
            var _local3:Item = (_local2) ? _local2 : null;
            if (this.canBuy(_local3)){
                this.onBuy(_local3);
            };
        }
        public function canBuy(_arg1:Item):Boolean{
            return (Global.player.checkGate(_arg1.unlock, _arg1.name));
        }
        public function onBuy(_arg1:Item):void{
            if (!_arg1){
                return;
            };
            var _local2:Boolean;
            if (_arg1.cash > 0){
                _local2 = Global.player.canBuyCash(_arg1.cash, false);
            } else {
                _local2 = Global.player.canBuy(_arg1.cost, true);
            };
            if (!_local2){
                if (_arg1.cash > 0){
                    UI.displayImpulseBuyPopup(ImpulseBuy.TYPE_MARKET_CASH);
                } else {
                    if (_arg1.cost > 0){
                        UI.displayImpulseBuyPopup(ImpulseBuy.TYPE_MARKET_COINS);
                    };
                };
                return;
            };
            dispatchEvent(new MarketEvent(MarketEvent.MARKET_BUY, MarketEvent.CONTRACT, _arg1.name, true));
            dispatchEvent(new Event(Event.CLOSE, true));
            this.onCloseClick();
        }

    }
}//package Display.FactoryUI 
